package com.medical.utils;

import lombok.extern.slf4j.Slf4j;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.function.Consumer;

/**
 * @author TISNIW
 * @version 1.0
 * @date 2025/6/22 0:16
 * @desc
 */
@Slf4j
public class StreamGobbler implements Runnable {
    private final InputStream inputStream;
    private final String streamType;
    private final Consumer<String> logger;

    public StreamGobbler(InputStream inputStream, String streamType, Consumer<String> logger) {
        this.inputStream = inputStream;
        this.streamType = streamType;
        this.logger = logger;
    }

    @Override
    public void run() {
        new BufferedReader(new InputStreamReader(inputStream))
                .lines()
                .forEach(line -> logger.accept("[" + streamType + "] " + line));
    }
}
